package cn.changeforyou.web.blog.luceneAop;

import cn.changeforyou.web.blog.service.LuceneService;
import lombok.extern.slf4j.Slf4j;
import org.nutz.aop.InterceptorChain;
import org.nutz.aop.MethodInterceptor;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import java.lang.reflect.Method;

/**
 * @author zhyu
 */
@Slf4j
@IocBean
public class LuceneMethodInterceptor implements MethodInterceptor {

    @Inject
    private LuceneService luceneService;

    @Override
    public void filter(final InterceptorChain chain) throws Throwable {

        Object[] args = chain.getArgs();
        Method method = chain.getCallingMethod();
        Lucene lucene = method.getDeclaredAnnotation(Lucene.class);
        LuceneOperate value = lucene.value();
        switch (value) {
            case add:
                chain.doChain();
                break;
            case update:
                chain.doChain();
                break;
            case remove:
                chain.doChain();
                break;
            case select:
                chain.doChain();
                break;
            case selectWhere:
                chain.doChain();
                break;
        }
    }
}
